package org.example;

//public class Main4 {
//    public static int factorial(int n1, int n2) {
//        // 基本情况：0 的阶乘是 1
//        if (n2 == 0) {
//            return n1 * 1;
//        } else {
//            // 递归步骤：n! = n * (n - 1)!
//            return factorial(n1 * n2, n2 - 1);
//        }
//    }
//
//    public static void main(String[] args) {
//        int number = 5;
//        int result = factorial(5, 4);
//        System.out.println(number + " 的阶乘是：" + result);
//    }
//}
//

import java.util.Arrays;

class TreeNode {
    int value;
    TreeNode left;
    TreeNode right;

    TreeNode(int value) {
        this.value = value;
    }
}

public class Main4 {
    public static void preOrderTraversal(TreeNode node) {
        if (node != null) {
            System.out.print(node.value + " ");
            preOrderTraversal(node.left);
            preOrderTraversal(node.right);
        }
    }

    public static void main(String[] args) {
        // 构建一个简单的二叉树
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        System.out.printf("root：%s",root);
        preOrderTraversal(root);
        System.out.println("前序遍历结果：");
        int[] numbers = {5, 2, 8, 1, 9};
        Arrays.sort(numbers);
        for (int num : numbers) {
            System.out.print(num + " ");
        }

        int index = Arrays.binarySearch(numbers, 5); // 使用Arrays.binarySearch()方法可以在已排序的数组中进行二分查找
        System.out.println("元素5的索引是: " + index);


        int[] originalArray = {1, 2, 3, 4, 5};
        int[] backupArray = Arrays.copyOf(originalArray, originalArray.length);

        // 修改原数组
        originalArray[0] = 10;

        System.out.println("Original Array: " + Arrays.toString(originalArray));
        System.out.println("Backup Array: " + Arrays.toString(backupArray));


    }
}